package com.lym.product.controller;

import com.lym.product.bean.Product;
import com.lym.product.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品控制器
 */
@Slf4j
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 获取商品信息
     *
     * 调用路径: http://localhost:9000/product/2
     *
     * @return
     */
    @GetMapping("/product/{id}")
    public Product getProduct(@PathVariable("id") Long productId,
                              HttpServletRequest request) {
        // 模拟日志打印,测试验证重试机制间隔时间
//        log.info("have a try");

        // 获取请求头,测试验证feign拦截器
        String header = request.getHeader("X-Token");
        System.out.println("X-Token:" + header);

        Product product = productService.getProductById(productId);
        return product;
    }

}
